const express = require("express");
const db = require("../../config/dbserver.js");
const router = express.Router();

// 记录用户数据 用户进入量
router.get(
  "/enter",
  async function (req, res) {
    console.log(req.query);

    const { type, content } = req.query;

    // await db.dbQuery(
    //   `INSERT INTO dev (type, content,created_at) VALUES (?, ?,now())`,
    //   [type || "null", content || "nothing"]
    // );

    res.send({
      code: 200,
      data: {},
      message: "success"
    });
  }
);

module.exports = router;








// 将错误记录到数据库的辅助函数
async function logError(oaid, errorObj) {
  try {
    const [log1Data] = await db.dbQuery("SELECT * FROM log1 WHERE oaid = ?", [
      oaid
    ]);
    if (!log1Data) {
      logger.error(`添加回传信息失败: 未找到对应的log1记录, oaid: ${oaid}`);
      return;
    }

    const errorInfo = parseJson(log1Data.error) || { info: [] };
    errorInfo.info.push(errorObj);

    await db.dbQuery("UPDATE log1 SET error = ? WHERE oaid = ?", [
      JSON.stringify(errorInfo),
      oaid
    ]);
  } catch (dbError) {
    logger.error(`数据库错误: 更新错误信息失败, ${dbError}`);
  }
}
